package hgx.spring.cloud.lession.usercenter.command;/**
 * Created by liujun on 2018/3/23.
 */

import com.netflix.hystrix.HystrixCommand;

import java.util.Random;
import java.util.concurrent.TimeUnit;

import hgx.spring.cloud.lession.orderserver.vo.ReponseOrderVo;
import hgx.spring.cloud.lession.usercenter.service.HelloService;

/**
 * @author Administrator
 * @create 2018-03-23 16:59
 */
public class OrderHystrixCommon  extends HystrixCommand<ReponseOrderVo>{
    private HelloService helloService;
    private Long orderNo;
    private final static Random RANDOM=new Random();

    public OrderHystrixCommon(Setter setter, HelloService helloService, Long orderNo) {
        super(setter);
        this.helloService = helloService;
        this.orderNo = orderNo;
    }

    @Override
    protected ReponseOrderVo run() throws Exception {
        int slTime=RANDOM.nextInt(360);
        TimeUnit.MILLISECONDS.sleep(slTime);
        ReponseOrderVo reponseOrderVo=helloService.orders(orderNo);
        return reponseOrderVo;
    }

    @Override
    protected ReponseOrderVo getFallback() {
        System.out.println("******************** call getFallback()  of  OrderHystrixCommon  ");
        return new ReponseOrderVo();
    }
}
